package d2_com.itheima.io;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * 编码和解码操作
 */
public class Code {
    public static void main(String[] args) throws UnsupportedEncodingException {
        //ASCll 字符集 只有英文、数字、符号等，占1个字节
        //GBK 国标汉字内码 汉字占2个字节，英文，数字占1个字节
        //Unicode 统一码万国码 UTF-32
        //UTF-8 汉字字符占3个字节，英文、数字等占1个字节
        //编码
        String data = "a我b";
        byte[] bytes = data.getBytes();//默认按照平台字符集
        System.out.println(Arrays.toString(bytes));

        byte[] bytes1 = data.getBytes("GBK");
        System.out.println(Arrays.toString(bytes1));

        //解码
        String s1 = new String(bytes);
        System.out.println(s1);

        String s2 = new String(bytes1,"GBK");
        System.out.println(s2);
    }
}
